#!/usr/bin/env python
#coding=utf-8
from Applications.libs.utils import reluesInfo
from flask import render_template,url_for,redirect,request,session,Response
from Applications.libs.redprint import Redprint
from Applications.services.AdminService import adminService
from Applications.forms import AdminsForms

login_redprint = Redprint('login')
@login_redprint.route('/',methods=['get','post'])
def admin_login():
    if request.method == 'POST':
        form = AdminsForms.admin_login()
        if not form.validate_on_submit():
            return reluesInfo(status=0,relues=form.errors).dumps()

        relust,admin_info,admin_menu = adminService.admin_login(form.admin_name.data, form.admin_passwd.data)
        if admin_info:
            session['admin_id'] = admin_info.admin_id
            session['admin_name'] = admin_info.admin_name
            session['admin_Jurisdiction']= admin_info.admin_Jurisdiction
            session['admin_JurisdictionType'] = admin_info.admin_JurisdictionType
            session['admin_menus'] = admin_menu

        return relust.dumps()

    return render_template("Admin/login.html")

@login_redprint.route('/loginout',methods=['get'])
def admin_loginout():
    return "admin_loginout"
